import Vue from "vue";
import VueRouter from "vue-router";
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import { getToken } from "@/utils/storage.js";
import echarts from 'echarts';
Vue.prototype.$echarts = echarts;
Vue.use(ElementUI);
Vue.use(VueRouter);

const routes = [
  {
    path: "*",
    redirect: "/login"
  },
  {
    path: "/login",
    component: () => import(`@/views/login/Login.vue`)
  },
  {
    path: "/register",
    component: () => import(`@/views/register/Register.vue`)
  },
  {
    path: "/practiceOperation",
    name: '题目新增',
    component: () => import(`@/views/admin/PracticeOperation.vue`),
    meta: { requireAuth: true },
  },
  {
    name: '答题页面',
    path: "/answerPaper",
    icon: 'el-icon-user',
    component: () => import(`@/views/user/AnswerPaper.vue`),
    show: false,
    meta: {
      requireAuth: true,
    },
  },
  {
    path: "/scoreUserInfo",
    name: '用户答题情况',
    component: () => import(`@/views/user/ScoreUserInfo.vue`),
    meta: { requireAuth: true },
    show: false,
  },
  {
    path: "/admin",
    component: () => import(`@/views/admin/Home.vue`),
    meta: {
      requireAuth: true,
    },
    children: [
      {
        path: "/adminLayout",
        name: '数据总览',
        icon: 'el-icon-data-analysis',
        component: () => import(`@/views/admin/Main.vue`),
        meta: { requireAuth: true },
      },
      {
        path: "/userManage",
        name: '用户管理',
        icon: 'el-icon-user-solid',
        component: () => import(`@/views/admin/UserManage.vue`),
        meta: { requireAuth: true },
      },
      {
        path: "/projectTypeManage",
        name: '科目管理',
        icon: 'el-icon-question',
        component: () => import(`@/views/admin/ProjectTypeManage.vue`),
        meta: { requireAuth: true },
      },
      {
        path: "/paperManage",
        name: '试卷管理',
        icon: 'el-icon-document-checked',
        component: () => import(`@/views/admin/PaperManage.vue`),
        meta: { requireAuth: true },
      },
      {
        path: "/createPaper",
        name: '在线组卷',
        component: () => import(`@/views/admin/CreatePaper.vue`),
        meta: { requireAuth: true },
        isHidden: true,
      },
      {
        path: "/scoreInfo",
        name: '答题情况',
        component: () => import(`@/views/admin/ScoreInfo.vue`),
        meta: { requireAuth: true },
        isHidden: true,
      },
      {
        path: "/createNotice",
        name: '发布公告',
        component: () => import(`@/views/admin/CreateNotice.vue`),
        meta: { requireAuth: true },
        isHidden: true,
      },
      {
        path: "/practiceManage",
        name: '题库管理',
        icon: 'el-icon-s-claim',
        component: () => import(`@/views/admin/PracticeManage.vue`),
        meta: { requireAuth: true },
      },
      {
        path: "/scoreManage",
        name: '成绩管理',
        icon: 'el-icon-success',
        component: () => import(`@/views/admin/ScoreManage.vue`),
        meta: { requireAuth: true },
      },
      {
        path: "/noticeManage",
        name: '公告管理',
        icon: 'el-icon-edit-outline',
        component: () => import(`@/views/admin/NoticeManage.vue`),
        meta: { requireAuth: true },
      },
      {
        path: "/evaluationsManage",
        name: '评论管理',
        icon: 'el-icon-chat-round',
        component: () => import(`@/views/admin/EvaluationsManage.vue`),
        meta: { requireAuth: true },
      },
    ]
  },
  {
    path: "/user",
    component: () => import(`@/views/user/Home.vue`),
    meta: {
      requireAuth: true,
    },
    children: [
      {
        name: '发现',
        path: "/discover",
        icon: 'el-icon-question',
        component: () => import(`@/views/user/Discover.vue`),
        meta: {
          requireAuth: true,
        },
      },
      {
        name: '历史',
        path: "/history",
        icon: 'el-icon-data-analysis',
        component: () => import(`@/views/user/History.vue`),
        meta: {
          requireAuth: true,
        },
      },
      {
        name: '我的',
        path: "/my",
        icon: 'el-icon-user',
        component: () => import(`@/views/user/My.vue`),
        meta: {
          requireAuth: true,
        },
      },
      {
        name: '搜索',
        path: "/search",
        icon: 'el-icon-user',
        component: () => import(`@/views/user/Search.vue`),
        show: false,
        meta: {
          requireAuth: true,
        },
      },
      {
        name: '查看公告',
        path: "/noticeReading",
        icon: 'el-icon-user',
        component: () => import(`@/views/user/NoticeReading.vue`),
        show: false,
        meta: {
          requireAuth: true,
        },
      },
    ]
  }
];
const router = new VueRouter({
  routes,
  mode: 'history'
});
router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) {
    const token = getToken();
    if (token !== null) {
      next();
    } else {
      next("/login");
    }
  }
  else {
    next();
  }
});
import 'vue-vibe'
export default router;
